<template>
  <div class="add">
    <van-nav-bar title="地址管理" left-text="返回" left-arrow @click-left="backhome"/>
        <div class="addresslist">
          <div class="addressitem" v-for="item in list" :key="item.id" @click="goOrder(item)">
            <div class="name">{{ item.name }}</div>
            <div class="mes">
                <p class="mes-mobile">{{ item.mobile }}</p>
                <p class="mes-address">{{ item.address }}</p>
                <p class="mes-detail">{{ item.address_detail }}</p>
            </div>
            <img src="@/assets/click.png" alt="" @click="goDetail(item)">
        </div>
        </div>

    <router-link class="addAddress" tag="div" :to="{name:'addressDetail'}">
        <div class="box">+新增地址</div>
    </router-link>
  </div>
</template>

<script>
import { getListAction } from "@/api/cart/order/address/index";
export default {
  name: "WorkspaceJsonIndex",

  data() {
    return {
      chosenAddressId: "1",
      list: [],
    };
  },

  created() {
    getListAction({
      openId: localStorage.getItem("openId"),
    }).then((res) => {
      console.log(res);
      this.list = res.data
    });
  },

  mounted() {},

  methods: {
    backhome(){
        this.$router.push('/cart/order')
    },
    goOrder(address){
      localStorage.setItem("addressInfo",JSON.stringify(address))
      this.$router.go(-1)
    },
    goDetail(val){
      this.$router.push({
        name:'addressDetail',
        params:{
          id:val
        }
      })
    }
  },
};
</script>

<style scoped lang="scss">
@import "../../scss/order/address/index.scss";
*{
  margin: 0px;
  padding: 0px;
}
</style>